package wq.gdky005.main;

import java.util.Properties;

import wq.gdky005.R;
import wq.gdky005.baidu.BaiDuUtils;
import wq.gdky005.util.ConfigUtil;
import wq.gdky005.util.TestUtils;
import android.app.Notification;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;

import com.baidu.android.pushservice.CustomPushNotificationBuilder;
import com.baidu.android.pushservice.PushConstants;
import com.baidu.android.pushservice.PushManager;

/**
 * 程序的主入口
 * @author wangqing
 * 2013-5-27
 */
public class MainActivity extends BaseActivity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		baiduPushStart();
		
		Properties properties = ConfigUtil.getConfig();
		TestUtils.logI(properties.getProperty("Name"));
	}
	
	@Override
    public void onStart() {
        super.onStart();

        PushManager.activityStarted(this);
    }

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
        PushManager.activityStoped(this);
	}
	
	@Override
    protected void onNewIntent(Intent intent) {
        // 如果要统计Push引起的用户使用应用情况，请实现本方法，且加上这一个语句
        setIntent(intent);
    }

	 /** 百度推送初始化 */
    private void baiduPushStart() {
        Resources resource = this.getResources();
        String pkgName = this.getPackageName();

        // 以apikey的方式登录，一般放在主Activity的onCreate中
        PushManager.startWork(getApplicationContext(),
                PushConstants.LOGIN_TYPE_API_KEY,
                BaiDuUtils.getMetaValue(MainActivity.this, "api_key"));


//        //设置自定义的通知样式，如果想使用系统默认的可以不加这段代码
        CustomPushNotificationBuilder cBuilder = new CustomPushNotificationBuilder(
                resource.getIdentifier("notification_custom_builder", "layout", pkgName),
                resource.getIdentifier("notification_icon", "id", pkgName),
                resource.getIdentifier("notification_title", "id", pkgName),
                resource.getIdentifier("notification_text", "id", pkgName));
        cBuilder.setNotificationFlags(Notification.FLAG_AUTO_CANCEL);
        cBuilder.setNotificationDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
        cBuilder.setStatusbarIcon(this.getApplicationInfo().icon);
        cBuilder.setLayoutDrawable(resource.getIdentifier("simple_notification_icon", "drawable", pkgName));
        PushManager.setNotificationBuilder(this, 1, cBuilder);



    }
}
